<template>
	<!-- 填冲砂智能计算 -->
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="套管内径(m)" prop="casingInnerDiameter">
				<u-input :border="border" placeholder="请输入套管内径" v-model="model.casingInnerDiameter" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="设计砂面深度(m)" prop="designSandDepth">
				<u-input :border="border" placeholder="请输入设计砂面深度" v-model="model.designSandDepth" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="目前人工井底深度(m)" prop="currentBottomDepth">
				<u-input :border="border" placeholder="请输入目前人工井底深度" v-model="model.currentBottomDepth" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="附加系数k" prop="additionalCoefficient">
				<u-input :border="border" placeholder="请输入附加系数(1.05-1.15)" v-model="model.additionalCoefficient" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;"  :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="填砂砂量" prop="sandVolume">
					<span v-if="model.sandVolume"> {{model.sandVolume}} L </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">V = (H - h) × π × (D/2)² × k</view>
				<view class="u-item-desc">式中：V — 填砂砂量，单位 L</view>
				<view class="u-item-desc">D — 套管内径，单位 m</view>
				<view class="u-item-desc">h — 设计砂面深度，单位 m</view>
				<view class="u-item-desc">H — 目前人工井底深度，单位 m</view>
				<view class="u-item-desc">k — 附加系数，取值在1.05-1.15之间</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					casingInnerDiameter: '',
					designSandDepth: '',
					currentBottomDepth: '',
					additionalCoefficient: '',
					sandVolume: ''
				},
				rules: {
					casingInnerDiameter: [{
						required: true,
						message: '请输入套管内径',
						trigger: 'blur'
					}],
					designSandDepth: [{
						required: true,
						message: '请输入设计砂面深度',
						trigger: 'blur'
					}],
					currentBottomDepth: [{
						required: true,
						message: '请输入目前人工井底深度',
						trigger: 'blur'
					}],
					additionalCoefficient: [{
						required: true,
						message: '请输入附加系数',
						trigger: 'blur'
					}, {
						validator: (rule, value, callback) => {
							const k = parseFloat(value);
							if (k < 1.05 || k > 1.15) {
								callback('附加系数必须在1.05-1.15之间');
							} else {
								callback();
							}
						},
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						const D = parseFloat(this.model.casingInnerDiameter);
						const h = parseFloat(this.model.designSandDepth);
						const H = parseFloat(this.model.currentBottomDepth);
						const k = parseFloat(this.model.additionalCoefficient);
						
						// V = (H - h) × π × (D/2)² ÷ 1000 × k
						this.model.sandVolume = ((H - h) * Math.PI * Math.pow(D/2, 2)  * k).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>